package com.qf.team2.netdisc.controller;

import com.qf.team2.netdisc.common.base.BaseController;
import com.qf.team2.netdisc.common.pojo.entity.Link;
import com.qf.team2.netdisc.common.pojo.qo.LinksDetails;
import com.qf.team2.netdisc.common.pojo.qo.ShareLinkQO;
import com.qf.team2.netdisc.common.pojo.vo.RespResultVO;
import com.qf.team2.netdisc.entity.Code;
import com.qf.team2.netdisc.service.ShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分享业务接口
 *
 * 设置好LINK类的属性，传递到数据库
 *
 * @author Simon_Wong
 * @date 2021/05/26 11:26
 */
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
@Controller
@RequestMapping("share")
@Api(tags = "分享业务接口")
public class ShareController extends BaseController<Object> {
    @Autowired
    private ShareService shareService;

    @ResponseBody
    @RequestMapping(value = "link", method = RequestMethod.POST)
    @ApiOperation("分享链接功能")
    public RespResultVO<Object> shareLink(@RequestBody ShareLinkQO shareLinkQO) {

        Link link = shareService.createLink(shareLinkQO);
        return successResp(link,"分享成功");
    }


    @ResponseBody
    @RequestMapping(value = "details",method = RequestMethod.POST)
    @ApiOperation("查询我的分享详情")
    public RespResultVO selectLinksDetails(@RequestParam("userId") int userId){
        System.out.println(userId);
        List<LinksDetails> newLinksDetails = shareService.selectLinksDetails(userId);
        return successResp(newLinksDetails,"查询成功");
    }
    @ResponseBody
    @RequestMapping(value = "cancel",method = RequestMethod.POST)
    public RespResultVO cancelShare(@RequestParam("linkId") int id){
        Integer i = shareService.updateIsPrivateStatus(id);
        return successResp(i,"取消成功");
    }
}
